
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%@ taglib prefix="his_fns" uri="/WEB-INF/tlds/his_fns.tld" %>
<script>
    $(function(){
        $("#btnCancel").on('click',function(){
            hideShowTableTd('contentTable','0,1,2,3,4,5,6','1');
            $("#RightDiv").attr("style","display: none");
            $("#LeftDiv").attr("class","main-content col-lg-12");
            $("#LeftDiv").show('normal');
        });
        $("#roomNo").on("change",function () {
            var  roomNo = $("#roomNo").val();
            var  bedId = $("#bedId").val();
            if(bedId==null||bedId==''){
                $.ajax({
                    type:'POST',
                    url:'${ctx}/nurse/bedRec/findMaxBedNo',
                    dataType:'json',
                    async:false,
                    success:function(data){
                        if(data!=null&&data!=''){
                            $('#bedNo').val(data);
                            if(Number(data)<10){
                                data="00"+data;
                            }else if(Number(data)<100){
                                data="0"+data;
                            }
                            $('#bedLabel').val(data);
                        }else{
                            $('#bedNo').val('');
                            $('#bedLabel').val('');
                        }
                    },
                    error:function(data){
                        toastr.error("网络错误！");
                    }
                });
            }
        });
    });
    autoCompleteClinic("airconditionItemDict");
    autoCompleteClinic("bedItemDict");
    function autoCompleteClinic(inputId) {
        if(inputId=="airconditionItemDict"){
            var url = "${ctx}/oper/clinicItemDict/automatic?itemClass=M";
        }else{
            var url = "${ctx}/oper/clinicItemDict/automatic?itemClass=J";
        }
        autoComplete(inputId, url,
                function (data) {
                    var rows = [];
                    for (var i = 0; i < data.length; i++) {
                        rows[rows.length] = {
                            data: data[i],
                            value: data[i].id,
                            result: data[i].itemName
                        };
                    }
                    return rows;
                }, function (data, i, max) {
                return data.inputCode + "|" + data.itemName + "|" + data.price+"元";
                }, function (event, data, formatted) {
                    if(inputId=="airconditionItemDict"){
                        $("#airconditionClass").val(data.id);
                    }else{
                        $("#bedGrade").val(data.id);
                    }

                })
    }

    function bedNoFun(noInput,labelInput){
        var operFlag = true;
        if(operFlag){
            var id = $('#bedId').val();
            var bedNo = $('#'+noInput).val();

            $.ajax({
                type:'POST',
                url:'${ctx}/nurse/bedRec/validIsExit?id='+id+'&bedNo='+Number(bedNo),
                dataType:'json',
                async:false,
                success:function(data){

                    if(data.code=='success'){
                        var data ;
                        if(Number(bedNo)<10){
                            data="00"+bedNo;
                        }else if(Number(bedNo)<100){
                            data="0"+bedNo;
                        }else{
                            data=bedNo;
                        }

                        $('#'+labelInput).val(data);
                        operFlag=false;
                    }else if(data.code=='error'){
                        toastr.error(data.data);
                        $('#'+noInput).val('');
                        operFlag = true;
                    }
                },
                error:function(data){
                    operFlag=false;
                    toastr.error("网络错误！");
                }
            })
        }

    }
</script>
<div class="content-wrap">
    <div class="wrapper" style="bottom: 50px;">
        <ul class="nav nav-tabs">
            <li>
                <a href="#">
                    <c:choose>
                        <c:when test="${bedRec.id==''|| bedRec.id==null}">
                            床位添加
                        </c:when>
                        <c:otherwise>床位修改</c:otherwise>
                    </c:choose>
                </a>
            </li>
        </ul>
        <section class="panel panel-default">
            <div class="panel-body">
                <div class="col-lg-12">
                    <form:form id="inputForm" data-parsley-validate=""  modelAttribute="bedRec"  method="post" class="form-horizontal" onsubmit='return  formSaveLoad("mainCenterDiv","inputForm","${ctx}/nurse/bedRec/save","${ctx}/nurse/bedRec/formList")'>
                        <form:hidden path="id" id="bedId"/>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">房间：</label>
                            <div class="col-sm-8">
                                <form:input path="roomNo" id="roomNo" htmlEscape="false" class="form-control" data-parsley-required="true" /><%--data-parsley-type="number" maxlength="4"去掉约束规则--%>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">床号：</label>
                            <div class="col-sm-8">
                                <input name="bedNo" id="bedNo" value="${bedRec.bedNo}" class="form-control" onchange="bedNoFun('bedNo','bedLabel')" maxlength="32" data-parsley-type="number" data-parsley-required="true" <c:if test="${bedRec.id!=null &&bedRec.id!=''}">readonly</c:if>/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">床标号：</label>
                            <div class="col-sm-8">
                                <input name="bedLabel"  id="bedLabel" value="${bedRec.bedLabel}" readonly class="form-control" data-parsley-required="true" maxlength="64" />
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">男/女：</label>
                            <div class="col-sm-8">
                                <form:select  path="bedSexType"  maxlength="64" class="form-control">
                                    <form:option value="" label="通用"/>
                                    <form:options items="${fns:getDictList('SEX_DICT')}"  htmlEscape="false" itemLabel="label" itemValue="value"/>
                                </form:select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">床位等级：</label>
                            <div class="col-sm-8">
                                <form:hidden path="bedGrade" id="bedGrade"/>
                                <input  id="bedItemDict" htmlEscape="false"
                                            class="form-control" maxlength="50" data-parsley-required="true" value="${his_fns:getClinicName(bedRec.bedGrade)}"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">空调等级：</label>
                            <div class="col-sm-8">
                                <form:hidden path="airconditionClass" id="airconditionClass"/>
                                <input  id="airconditionItemDict" htmlEscape="false"
                                        class="form-control" maxlength="50"  value="${his_fns:getClinicName(bedRec.airconditionClass)}"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">类型：</label>
                            <div class="col-sm-8">
                                <form:select  path="bedApprovedType"  maxlength="64" class="form-control" data-parsley-required="true">
                                    <form:options items="${fns:getDictList('BED_APPROVED_TYPE_DICT')}"  htmlEscape="false" itemLabel="label" itemValue="value"/>
                                </form:select>
                            </div>
                        </div>
                        <c:if test="${bedRec.id==null || bedRec.id==''}">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">空床：</label>
                                <div class="col-sm-8">
                                    <input name="bedStatus" value="1" class="form-control" type="hidden"/>
                                    <input name="status" value="是" class="form-control" readonly/>
                                    <%--<form:select  path="bedStatus"  maxlength="64" class="form-control" data-parsley-required="true">
                                        <form:option label="" value=""/>
                                        <form:options items="${fns:getDictList('YES_NO')}" itemValue="value" itemLabel="label"></form:options>
                                    </form:select>--%>
                                </div>
                            </div>
                        </c:if>


                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <input id="btnSubmit" class="btn btn-primary" type="submit" value="保存">&nbsp;
                                <input id="btnCancel" class="btn" type="button" value="关 闭" ></div>
                        </div>
                    </form:form>
                </div>
                <input type="hidden" id="price" value="">
            </div>
        </section>
    </div>
</div>

